//
//  Game.cpp
//  Space shooting
//
//  Created by Raiden on 9/19/13.
//
//

#include "Game.h"
#include "Constants.h"
#include "Enemy01.h"

static Game *game = NULL;

Game::Game() {
    
    size = CCDirector::sharedDirector()->getWinSize();
    resetData();
}

void Game::resetData() {
    
    gameStatus = GAME_STATUS_NORMAL;
    
    gameScore = 0;
    
    enemyList = new CCArray;
    bulletList = new CCArray;
    orbList = new CCArray;
}

Game::~Game() {
    
    if(enemyList) {
        
        enemyList->release();
        enemyList = NULL;
    }
    
    if(bulletList) {
        bulletList->release();
        bulletList = NULL;
    }
}

Game* Game::getInstance() {
    
    if(game == NULL) {
        
        game = new Game;
    }
    
    return game;
}

// Wave from right with bezier
void Game::waveType01() {
    
    Enemy01 *enemy = Enemy01::create("ship_02.png");
    
    ccBezierConfig config;
    config.controlPoint_1 = ccp(size.width/2, size.height);
    config.controlPoint_2 = ccp(0, size.height/2);
    config.endPosition = ccp(size.width, 0 - enemy->getContentSize().height/2);
    
    CCBezierTo *move = CCBezierTo::create(3.0, config);
    
    enemy->setPosition(ccp(size.width, size.height));
    enemy->runAction(move);
    
    EnemyList->addObject(enemy);
    MainScene->addChild(enemy);
}

// Wave from left with bezier
void Game::waveType02() {
    
    Enemy01 *enemy = Enemy01::create("ship_03.png");
    
    ccBezierConfig config;
    config.controlPoint_1 = ccp(0, size.height);
    config.controlPoint_2 = ccp(size.width, size.height/2);
    config.endPosition = ccp(0, 0 - enemy->getContentSize().height/2);
    
    CCBezierTo *move = CCBezierTo::create(3.0, config);
    
    enemy->setPosition(ccp(0, size.height));
    enemy->runAction(move);
    
    EnemyList->addObject(enemy);
    MainScene->addChild(enemy);
}

// Wave from right move toward
void Game::waveType03() {
    
    Enemy01 *enemy = Enemy01::create("ship_05.png");
    
    CCMoveTo *move = CCMoveTo::create(3.0, ccp(0 - enemy->getContentSize().width/2, size.height/2));
    
    enemy->setPosition(ccp(size.width, size.height/4));
    enemy->runAction(move);
    
    EnemyList->addObject(enemy);
    MainScene->addChild(enemy);
}

// Wave from left move toward
void Game::waveType04() {
    
    Enemy01 *enemy = Enemy01::create("ship_06.png");
    
    CCMoveTo *move = CCMoveTo::create(3.0, ccp(size.width + (enemy->getContentSize().width/2), size.height/2));
    
    enemy->setPosition(ccp(0, size.height/4));
    enemy->runAction(move);
    
    EnemyList->addObject(enemy);
    MainScene->addChild(enemy);
}